package WarTug;

import org.lwjgl.input.Keyboard;
import org.newdawn.slick.opengl.Texture;


// It may seem odd that TextField inherits from Button.  However, it is 
// essentially a Button whose string is changeable by the user.  

public class TextField extends Button{

	private boolean focused = false;
	private final int MAX_CHARS = 20;
	
	public TextField(double x, double y, double width, double height) {
		super(x, y, width, height);
	}

	public TextField(double x, double y, double width, double height,
			String text) {
		super(x, y, width, height, text);
	}
	
	public TextField(double x, double y, double width, double height, String text, Texture tex) {
		super(x, y, width, height, text, tex);
	}

	public TextField(double x, double y, double width, double height,
			Texture texture) {
		super(x, y, width, height, texture);
	}
	
	public TextField(double x, double y, double width, double height,
			String text, Texture texture, ButtonAction action) {
		super(x, y, width, height, text, texture, action);
	}

	public void setFocused(boolean focused) {
		this.focused = focused;
	}

	public boolean isFocused() {
		return focused;
	}
	
	public void addChar(int eventKey, char eventChar){
		if ((eventKey == Keyboard.KEY_BACK || eventKey == Keyboard.KEY_DELETE) && text.length() > 0){
			text = text.substring(0, text.length()-1);
		} else if (text.length() < MAX_CHARS && (((int)Keyboard.getEventCharacter()>=32 && (int)Keyboard.getEventCharacter()<=126))){
			text = text + eventChar;
		}
	}
	
	
	
	
	
	
	

	
	
	
}
